<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Spot extends Model
{
    protected $table = 'spots';

    public function basePicture()
    {
        return $this->hasMany(BasePicture::class);
    }

    public function onePicture()
    {
        return $this->hasOne(BasePicture::class);

    }

    public function baseReply()
    {
        return $this->hasMany(BaseReply::class);
    }
    //利用『模型事件』来实现删除数据时的连带删除
    protected static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub

        static::deleting(function ($spot){
           $spot->basePicture()->delete();
           $spot->baseReply()->delete();
        });
    }

}
